package com.zz.yt.test.gloading;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.whf.android.jar.view.font.FontSizeView;
import com.zz.yt.test.R;


public class FontSizeActivity extends Activity {

    TextView mFactTextView;
    boolean is;

    // 字体大小不跟随系统
    @Override
    protected void attachBaseContext(@NonNull Context newBase) {
        Configuration configuration = newBase.getResources().getConfiguration();
        configuration.fontScale = 1;
        super.attachBaseContext(newBase.createConfigurationContext(configuration));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_font_size);
        mFactTextView = findViewById(R.id.id_text_name);
        setTextAnimate(mFactTextView);
    }

    /**
     * 改变textsize 大小
     */
    private void changeTextSize(int dimension) {
//        tv_font_size1.setTextSize(dimension);
//        tv_font_size2.setTextSize(dimension);
//        tv_font_size3.setTextSize(dimension);
    }


    private void setTextAnimate(final View view) {
        final int sec = 500;
        final float xBy = 0.7f, yBy = 0.2f;
        if (view != null) {
            view.animate()
                    //是否开启硬件加速
                    .withLayer()
                    .setDuration(sec)
                    .translationX(20)
                    .scaleXBy(xBy)
                    .scaleYBy(yBy)
                    .setListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (is) {
                                view.animate().withLayer()
                                        .setDuration(sec)
                                        .translationX(20)
                                        .scaleXBy(xBy)
                                        .scaleYBy(yBy);
                            } else {
                                view.animate().withLayer()
                                        .setDuration(sec)
                                        .translationX(0)
                                        .scaleX(1f)
                                        .scaleY(1f);
                            }
                            is = !is;
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
        }

    }

}
